package base.collection_demo.demo03;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Objects;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class PersonComparable implements Comparable{
    private String name;
    private Integer age;

    @Override
    public int compareTo(Object o) {
        return 1;
    }

    // name 和 age 是否分别 equals 比较
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PersonComparable that = (PersonComparable) o;
        return name.equals(that.name) && age.equals(that.age);
    }

    // name 和 age 字面相等的情况下，该方法返回的哈希值相同。
    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

}
